﻿using UnityEngine;
using Core;

public class EnemyFollow : Entity, IUpdate, IAwake<Unit>
{
    public Unit target;

    private Unit self;
    private float speed = 0.1f;

    void IAwake<Unit>.Awake(Unit target)
    {
        self = GetParent<Unit>();
        this.target = target;
        this.speed = self.GetComponent<NumericComponent>().GetAsFloat(NumericType.moveSpeed);
    }

    void IUpdate.Update()
    {
        self.Position = Vector3.MoveTowards(self.Position, target.Position, speed * Time.deltaTime);
        self.transform.LookAt(target.transform);
    }
}
